<?
//本文档存放网站常用的函数，直接供一次过记录多个函数，让系统使用

function print_r2($array)
{
    echo "<pre>";
    print_r($array);
    echo "</pre>";
}

//================================
// 获取当前路径包含前缀及路径及参数
//================================



function curPageURL()
{
  $pageURL = 'http';

  if ($_SERVER["HTTPS"] == "on")
  {
    $pageURL .= "s";
  }
  $pageURL .= "://";

  if ($_SERVER["SERVER_PORT"] != "80")
  {
    $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
  }
  else
  {
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
  }
  return $pageURL;
}


function check_user_account($user_mid){

	$userinfo = select_one_line_all_items($table_Prefix."user","mid = '".$user_mid."'");


	$config_info = select_one_line_all_items("config","id = '1'");

	if($userinfo['balance'] < $config_info['user_account']){
		send_msg();
	}

}

function send_msg(){

}

function cat_list($cat_id = 0, $selected = 0, $re_type = true, $level = 0, $res = '')
{

    global $table_Prefix;

	static $res = NULL;
    if ($res === NULL)
    {
       $data = read_static_cache('cat_pid_releate');

       if ($data === false)
       {
          $sql = "SELECT c.* , COUNT(s.nid) AS has_children ".
                'FROM ' . $table_Prefix.'department' . " AS c ".
                "LEFT JOIN " . $table_Prefix.'department' . " AS s ON s.parent_id=c.nid ".
                "GROUP BY c.nid ".
                'ORDER BY c.parent_id, c.nid ASC';


		  $result_term0 = do_query($sql);

          while($row = mysqli_fetch_array($result_term0))
          {
              $res[]=$row;

          }


		  //如果数组过大，不采用静态缓存方式
          if (count($res) <= 1000)
          {
              write_static_cache('cat_pid_releate', $res);

          }
        }
        else
        {
            $res = $data;
        }

    }

    if (empty($res) == true)
    {
        return $re_type ? '' : array();
    }

    $options = cat_options($cat_id, $res); // 获得指定分类下的子分类的数组

    $children_level = 99999; //大于这个分类的将被删除

        foreach ($options as $key => $val)
        {
            if ($val['level'] > $children_level)
            {
                unset($options[$key]);
            }
            else
            {
                if ($val['status'] == '关闭')
                {
                    unset($options[$key]);
                    if ($children_level > $val['level'])
                    {
                        $children_level = $val['level']; //标记一下，这样子分类也能删除
                    }
                }
                else
                {
                    $children_level = 99999; //恢复初始值
                }
            }
        }


    /* 截取到指定的缩减级别 */
    if ($level > 0)
    {
        if ($cat_id == 0)
        {
            $end_level = $level;
        }
        else
        {
            $first_item = reset($options); // 获取第一个元素
            $end_level  = $first_item['level'] + $level;
        }

        /* 保留level小于end_level的部分 */
        foreach ($options AS $key => $val)
        {
            if ($val['level'] >= $end_level)
            {
                unset($options[$key]);
            }
        }
    }

    if ($re_type == true)
    {
        $select = '';
        foreach ($options AS $var)
        {
            $select .= '<option value="' . $var['nid'] . '" ';
            $select .= ($selected == $var['nid']) ? "selected='ture'" : '';
            $select .= '>';
            if ($var['level'] > 0)
            {
                $select .= str_repeat('&nbsp;', $var['level'] * 4);
            }
            $select .= htmlspecialchars(addslashes($var['name']), ENT_QUOTES) . '</option>';
        }

        return $select;
    }
    else
    {
        foreach ($options AS $key => $value)
        {
           // $options[$key]['url'] = build_uri('category', array('cid' => $value['cat_id']), $value['cat_name']);
        }

        return $options;
    }
}





/**
 * 过滤和排序所有分类，返回一个带有缩进级别的数组
 *
 * @access  private
 * @param   int     $cat_id     上级分类ID
 * @param   array   $arr        含有所有分类的数组
 * @param   int     $level      级别
 * @return  void
 */
function cat_options($spec_cat_id, $arr)
{
    static $cat_options = array();


    if (isset($cat_options[$spec_cat_id]))
    {
        return $cat_options[$spec_cat_id];
    }

    if (!isset($cat_options[0]))
    {

        $level = $last_cat_id = 0;
        $options = $cat_id_array = $level_array = array();
        $data = false;
        if ($data === false)
        {
            while (!empty($arr))
            {
                foreach ($arr AS $key => $value)
                {
                    $cat_id = $value['nid'];
                    if ($level == 0 && $last_cat_id == 0)
                    {

                        if ($value['parent_id'] > 0)
                        {
                            break;
                        }

                        $options[$cat_id]          = $value;
                        $options[$cat_id]['level'] = $level;
                        $options[$cat_id]['id']    = $cat_id;
                        $options[$cat_id]['name']  = $value['name'];

                        unset($arr[$key]);

                        if ($value['has_children'] == 0)
                        {
                            continue;
                        }
                        $last_cat_id  = $cat_id;
                        $cat_id_array = array($cat_id);
                        $level_array[$last_cat_id] = ++$level;
                        continue;
                    }

                    if ($value['parent_id'] == $last_cat_id)
                    {

                        $options[$cat_id]          = $value;
                        $options[$cat_id]['level'] = $level;
                        $options[$cat_id]['id']    = $cat_id;
                        $options[$cat_id]['name']  = $value['name'];
                        unset($arr[$key]);

                        if ($value['has_children'] > 0)
                        {
                            if (end($cat_id_array) != $last_cat_id)
                            {
                                $cat_id_array[] = $last_cat_id;
                            }
                            $last_cat_id    = $cat_id;
                            $cat_id_array[] = $cat_id;
                            $level_array[$last_cat_id] = ++$level;
                        }
                    }
                    elseif ($value['parent_id'] > $last_cat_id)
                    {
                        break;
                    }
                }

                $count = count($cat_id_array);
                if ($count > 1)
                {
                    $last_cat_id = array_pop($cat_id_array);
                }
                elseif ($count == 1)
                {
                    if ($last_cat_id != end($cat_id_array))
                    {
                        $last_cat_id = end($cat_id_array);
                    }
                    else
                    {
                        $level = 0;
                        $last_cat_id = 0;
                        $cat_id_array = array();
                        continue;
                    }
                }

                if ($last_cat_id && isset($level_array[$last_cat_id]))
                {
                    $level = $level_array[$last_cat_id];
                }
                else
                {
                    $level = 0;
                }
            }

        }
        else
        {
            $options = $data;
        }
        $cat_options[0] = $options;
    }
    else
    {
        $options = $cat_options[0];
    }

    if (!$spec_cat_id)
    {
        return $options;
    }
    else
    {

        if (empty($options[$spec_cat_id]))
        {
            return array();
        }

        $spec_cat_id_level = $options[$spec_cat_id]['level'];

        foreach ($options AS $key => $value)
        {

            if ($key != $spec_cat_id)
            {

                unset($options[$key]);
            }
            else
            {
                break;
            }
        }

        $spec_cat_id_array = array();
        foreach ($options AS $key => $value)
        {
            if (($spec_cat_id_level == $value['level'] && $value['nid'] != $spec_cat_id) ||
                ($spec_cat_id_level > $value['level']))
            {
                break;
            }
            else
            {
                $spec_cat_id_array[$key] = $value;
            }
        }
        $cat_options[$spec_cat_id] = $spec_cat_id_array;

        return $spec_cat_id_array;
    }
}


function get_department_list(){

	 global $table_Prefix;
 	$sql = "SELECT c.* , COUNT(s.nid) AS has_children ".
                'FROM ' . $table_Prefix.'department' . " AS c ".
                "LEFT JOIN " . $table_Prefix.'department' . " AS s ON s.parent_id=c.nid ".
                "GROUP BY c.nid ".
                'ORDER BY c.parent_id, c.nid ASC';

	$result_term0 = do_query($sql);

    while($row = mysqli_fetch_array($result_term0))
    {
       $res[]=$row;
    }
	return $res;
}

function get_department_top_id($id){

	global $table_Prefix;

	$father_id = '';

	$department_info = select_one_line_all_items($table_Prefix."department","nid=".$id);

	$father_id = $department_info['nid'];
	if($department_info['parent_id'] > 0){

		return get_department_top_id($department_info['parent_id']);

	}

	return $father_id;

}

/**
 * 获得指定分类下所有底层分类的ID
 *
 * @access  public
 * @param   integer     $cat        指定的分类ID
 * @return  string
 */
function get_children($cat = 0,$res = '')
{
    return  db_create_in(array_unique(array_merge(array($cat), array_keys(cat_list($cat, 0, false,0,$res)))));
}

/**
 * 创建像这样的查询: "IN('a','b')";
 *
 * @access   public
 * @param    mix      $item_list      列表数组或字符串
 * @param    string   $field_name     字段名称
 *
 * @return   void
 */

function db_create_in($item_list, $field_name = '')
{
    if (empty($item_list))
    {
        return $field_name . " IN ('') ";
    }
    else
    {
        if (!is_array($item_list))
        {
            $item_list = explode(',', $item_list);
        }
        $item_list = array_unique($item_list);
        $item_list_tmp = '';
        foreach ($item_list AS $item)
        {
            if ($item !== '')
            {
                $item_list_tmp .= $item_list_tmp ? ",'$item'" : "'$item'";
            }
        }
        if (empty($item_list_tmp))
        {
            return $field_name . " IN ('') ";
        }
        else
        {
            return $field_name . ' IN (' . $item_list_tmp . ') ';
        }
    }
}


function admin_priv($priv_str)
{

    if ($_SESSION['quanxian'] == 'all')
    {
        return true;
    }

	$quanxian_list = explode(',',$_SESSION['quanxian']);


    if (!in_array($priv_str,$quanxian_list))
    {

        echo '<script>alert("对不起,您没有执行此项操作的权限!");window.location.href="../index.php?nav-itemed=index";</script>';

        return false;
    }
    else
    {
        return true;
    }
}



/**
 * 读结果缓存文件
 *
 * @params  string  $cache_name
 *
 * @return  array   $data
 */
function read_static_cache($cache_name)
{
    if ((DEBUG_MODE & 2) == 2)
    {
        return false;
    }
    static $result = array();
    if (!empty($result[$cache_name]))
    {
        return $result[$cache_name];
    }
    $cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
    if (file_exists($cache_file_path))
    {
        include_once($cache_file_path);
        $result[$cache_name] = $data;
        return $result[$cache_name];
    }
    else
    {
        return false;
    }
}

/**
 * 写结果缓存文件
 *
 * @params  string  $cache_name
 * @params  string  $caches
 *
 * @return
 */
function write_static_cache($cache_name, $caches)
{
    if ((DEBUG_MODE & 2) == 2)
    {
        return false;
    }

    $cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
    $content = "<?php\r\n";
    $content .= "\$data = " . var_export($caches, true) . ";\r\n";
    $content .= "?>";
    file_put_contents($cache_file_path, $content, LOCK_EX);

}


function clear_cache(){

	unlink(ROOT_PATH . '/temp/static_caches/cat_pid_releate.php');

}


// 1. 生成原始的二维码(生成图片文件)
/*function scerweima($url=''){
  require_once ROOT_PATH.'/application/phpqrcode/phpqrcode.php';
  $value = $url;         //二维码内容
  $errorCorrectionLevel = 'L';  //容错级别
  $matrixPointSize = 5;      //生成图片大小
  //生成二维码图片
  $filename = ROOT_PATH.'qrcode/'.microtime().'.png';
  QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
  $QR = $filename;        //已经生成的原始二维码图片文件
  $QR = imagecreatefromstring(file_get_contents($QR));
  //输出图片
  imagepng($QR, 'qrcode.png');
  imagedestroy($QR);
  return '<img src="'.ROOT_PATH.'qrcode.png" alt="使用微信扫描支付">';
}*/

function scerweima2($url=''){
  require_once ROOT_PATH.'/application/phpqrcode/phpqrcode.php';
  $value = $url;         //二维码内容
  $errorCorrectionLevel = 'L';  //容错级别
  $matrixPointSize = 5;      //生成图片大小

   $object = new QRcode();
   $errorCorrectionLevel = 'L';    //容错级别
   $matrixPointSize = 5;            //生成图片大小

   //打开缓冲区
   ob_start();
   //生成二维码图片
  $returnData = $object->png($value,false,$errorCorrectionLevel, $matrixPointSize, 2);

  //这里就是把生成的图片流从缓冲区保存到内存对象上，使用base64_encode变成编码字符串，通过json返回给页面。
  $imageString = base64_encode(ob_get_contents());
  //关闭缓冲区
  ob_end_clean();
  $base64 = "data:image/png;base64,".$imageString;
   return $base64;
}
function insert_refund_order($data)
{
    global $table_Prefix;
    $sql = insert_date($table_Prefix . 'event_refund_log',$data);

    return do_query($sql);

}


function update_order($order_sn,$status,$pay_log=[] , $refund_price='0.00') //status 2 已经付款   3取消
{

    //    0待付款 1已付款 2已退款  3待退款

    global $table_Prefix;
    global $domain;
    $order_info = select_one_line_all_items($table_Prefix . 'order_info', "order_sn = '$order_sn'");

    //print_r2($order_info);

    if($order_info)
    {

        $user_info = select_one_line_all_items($table_Prefix . 'member', "nid = '{$order_info['user_id']}'");

        //本来写了status=0的，但是如果免单券的话，前面调用之前，会直接把status改成2，所以应该包含1
        if($status == 2 && $order_info['order_status'] <= 1)
        {

            //20250706 支付成功之后，为配送日程添加信息
            //支付成功之后，就从这个订单查找用户信息，插入order_detail

//20250906
            //如果系统卡顿，订单会重复生成，这里判断一下，如果已经生成了配送日程，就不重复生成了
            $order_detail_info = select_one_line_all_items($table_Prefix . 'order_detail'," order_nid = '{$order_info['order_id']}' ");

            if(!$order_detail_info)
            {

                $_schedule=select_lines_all_items($table_Prefix . 'product_schedule',
                                                  'nid asc',
                                                  "product_nid = '{$order_info['product_id']}'","");


                //提取订单日期，用于循环生成detail
                $order_startdate = $order_info['startdate'];
                $order_enddate   = $order_info['enddate'];
                $order_adddate   = $order_info['add_date']; //用户下单的时间

                foreach ($_schedule as $k=> $schedule)
                {
                    $_order_detail['ai_order_nid'] = $order_info['order_id'];
                    $_order_detail['ai_ondate'] = $schedule['apply_date'];
                    $_order_detail['ai_product_nid'] = $order_info['product_id'];
                    $_order_detail['ai_student_nid'] = $order_info['student_nid'];
                    $_order_detail['ai_user_nid'] = $order_info['user_id'];
                    $_order_detail['ai_name'] = $order_info['student_name'];
                    $_order_detail['ai_price'] = "0.0";
                    $_order_detail['ai_number'] = "1";
                    //$i是循环到的日期
                    //如果下单时间=$i 或者>$i，意味着迟于开始服务的时间，则状态为未配送。
                    if ($order_adddate >= $schedule['apply_date'])
                    {
                        $_order_detail['ai_status'] = "过期未配送";
                    }
                    else
                    {
                        $_order_detail['ai_status'] = "正常";
                    }
                    $_order_detail['ai_product_name'] = $schedule['milk_name'];
                    $_order_detail['ai_order_name'] = $order_info['order_name'];
                    $_order_detail['ai_add_date'] = date("Y-m-d H:i:s"); // 当前日期和时间
                    $_order_detail['ai_school'] = $order_info['student_school'];
                    $_order_detail['ai_grade']  = $order_info['student_grade'];
                    $_order_detail['ai_class_'] = $order_info['student_class'];

                    $_sql=insert_data($table_Prefix."order_detail",$_order_detail);

                    do_query($_sql) or die($_sql);

                }
            }





            //echo "执行状态2";
            $update_data['ai_order_status']   = 1;
            $update_data['ai_pay_status']     = 1;
            $update_data['ai_transaction_id'] = $pay_log ? $pay_log['transaction_id'] : '';
            $update_data['ai_pay_log']        = $pay_log ? json_encode($pay_log) : '';
            $sql = update_date($table_Prefix . 'order_info',$update_data,'order_id',$order_info['order_id']);
            $res = do_query($sql);





        }

        //待退款状态是3，但是有些是已经付款了的
        elseif($status == 4 && ($order_info['pay_status'] == 3 or $order_info['pay_status'] == 1 ))
        {

            $update_data['ai_order_status'] = 2;
            $update_data['ai_pay_status'] = 2;

            $sql = update_date($table_Prefix . 'order_info',$update_data,'order_id',$order_info['order_id']);
            $res = do_query($sql);

        }
        elseif($status == 3 && $order_info['pay_status'] == 1 && $order_info['order_status'] == 1){

            $update_data['ai_order_status'] = 1;
            $update_data['ai_pay_status'] = 3;
            $update_data['ai_refund_price'] = bcadd($order_info['refund_price'],$refund_price/100 ,2);

            $sql = update_date($table_Prefix . 'order_info',$update_data,'order_id',$order_info['order_id']);

            $res = do_query($sql);

        }

    }
    return true;
}














function domain_img(){

   return  "https://".$_SERVER['SERVER_NAME'].'/uploadfiles/event/';

}

function domain_memberimg(){

    return  "https://".$_SERVER['SERVER_NAME'].'/uploadfiles/member/';

}

function domain_leader_img(){

    return  "https://".$_SERVER['SERVER_NAME'].'/uploadfiles/leader/';

}

function getHeaders()
{
    $header                = array();
    foreach ($_SERVER as $key => $value) {
        if ('HTTP_' == substr($key, 0, 5)) {
            $header[str_replace('_', '-', substr($key, 5))] = $value;
        }
        if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
            $header['AUTHORIZATION'] = $_SERVER['PHP_AUTH_DIGEST'];
        } elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
            $header['AUTHORIZATION'] = base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
        }
        if (isset($_SERVER['CONTENT_LENGTH'])) {
            $header['CONTENT-LENGTH'] = $_SERVER['CONTENT_LENGTH'];
        }
        if (isset($_SERVER['CONTENT_TYPE'])) {
            $header['CONTENT-TYPE'] = $_SERVER['CONTENT_TYPE'];
        }
    }
    return $header;
}









//检查活动状态
//用于自动成局，自动流局，自动退款等操作。
function check_event_status($event_info){


    echo "当前活动id".$event_info['nid'];

    global $table_Prefix;
    global $domain;


    //获取活动的参与人员,记得排除已经退款的。
    $member_list = select_lines_all_items($table_Prefix."event_member",'nid desc' , 'event_nid ='.$event_info['nid']." and is_delete = 0");

    $join_total_member = 0;
    $event_info['join_male_member'] = 0;
    $event_info['join_female_member'] = 0;
    if($member_list){
        foreach ($member_list as $key2=>$item){
            $join_total_member++;
            if($item['sex'] == 1 ){
                $event_info['join_male_member']++;
            }
            else{
                $event_info['join_female_member']++;
            }
        }
    }
    $min_join_status = 0;
    $female_join_status = 0;


    //如果是1，则表示达到最少女性
    if( $event_info['join_female_member'] >= $event_info['female_member']){

        $female_join_status = 1;
    }

    //如果是1，则表示达到最少人数
    if( $event_info['min_member'] <= $join_total_member){

        $min_join_status = 1;
    }


//    var_dump($min_join_status);
//    var_dump($female_join_status);


    //参团人员数 和 女性人员数 去判断是否成局
    //把所有成员的信息都提取，准备用来发送通知。

    $_member_nid=transform_2darray_in_1darray_number_as_key($member_list,"user_id");
    $_member_nid_str=implode("','",$_member_nid);

    $_member_unionid_list=select_lines_items($table_Prefix."member","","unionid","nid in ('".$_member_nid_str."')","");
    $_member_unionid_list_array=transform_2darray_in_1darray_number_as_key($_member_unionid_list,"unionid");
    $_member_unionid_list_str=implode("','",$_member_unionid_list_array);

    $member_openid=select_lines_items($table_Prefix."wechat_member","","openid","unionid in ('".$_member_unionid_list_str."')","");

   // print_r($member_openid);







    //每次检查未成局的活动，小于号表示报名结束时间，是现在时间之前。就是活动已经结束了。
    if(
        strtotime($event_info['apply_endtime']) < time()

        //下面这个判断就是，一旦够最低人数，就自动成局，但是据说判断是要达到最大人数才自动成局
        //or ($min_join_status == 1 && $female_join_status == 1)

      )
    {

            if($min_join_status == 1 && $female_join_status == 1)
            {

                    $sql = "update ".$table_Prefix."event set event_status = 1 where  nid =".$event_info['nid'];
                    do_query($sql);

                    //成局的通知
                    echo "组局成功";
                    //1.从member中获取unionid，再换取openid，再循环
                    foreach ( $member_openid as $k=>$v)
                    {
                        //curl 一个api地址，带上通知内容代号，被通知人，然后就触发了。
                        echo $_url=$domain."/api/wechat_message/notice_event_success.php?openid=".$v['openid']."&eventid=".$event_info['nid'];
                        echo "<br/>";

                        file_get_contents($_url);

                    }

                //给局长发送通知
                $leader = select_one_line_all_items($table_Prefix."member",' nid='.$event_info['employee_id']);
                $wechat_member = select_one_line_all_items($table_Prefix."wechat_member","unionid = '".$leader['unionid']."'");

                //curl 一个api地址，带上通知内容代号，被通知人，然后就触发了。
                $_url=$domain."/api/wechat_message/notice_event_success.php?openid=".$wechat_member['openid']."&eventid=".$event_info['event_id'];
                file_get_contents($_url);


            }

            else{
                    echo "组局失败";

                    $sql = "update ".$table_Prefix."event set event_status = 2 where  nid =".$event_info['nid'];
                    do_query($sql);


                    //不成局
                    //1.从member中获取unionid，再换取openid，再循环通知
                    foreach ( $member_openid as $k=>$v)
                    {
                        //curl 一个api地址，带上通知内容代号，被通知人，然后就触发了。
                        echo $_url=$domain."/api/wechat_message/notice_event_failed.php?openid=".$v['openid']."&eventid=".$event_info['nid'];
                        echo "<br/>";

                        file_get_contents($_url);


                    }

                //给局长发送通知
                $leader = select_one_line_all_items($table_Prefix."member",' nid='.$event_info['employee_id']);
                $wechat_member = select_one_line_all_items($table_Prefix."wechat_member","unionid = '".$leader['unionid']."'");
                //curl 一个api地址，带上通知内容代号，被通知人，然后就触发了。
                $_url=$domain."/api/wechat_message/notice_event_failed.php?openid=".$wechat_member['openid']."&eventid=".$event_info['event_id'];
                file_get_contents($_url);


                echo "<br/>";
                echo "<br/>";
                echo "<br/>不成局 则循环退款";



                //不成局 则循环退款
                //1.函数开头获取的member list 是参与活动的人
                //注意，退款价钱不要看活动的价格，因为有人用的优惠券，可能支付的不是原价

                //找出所有该活动的订单
                //该订单需要未退款项的
                $this_order=select_lines_all_items($table_Prefix."order_info","",
                                                   "event_id = '".$event_info['nid']."' and pay_status = '1'","9990");

                print_r2($this_order);


                foreach ( $this_order as $k2=>$v2)
                {

                    //获取这个活动中的人
                    $event_member_info = select_one_line_all_items($table_Prefix.'event_member',
                                                                   "user_id = '".$v2['user_id']."' and 
                                                                             event_nid = '".$event_info['nid']."' and 
                                                                             is_delete = 0 ");

                    echo "此人活动中的nid";
                    print_r2($event_member_info);

                    //curl
                    echo $_url=$domain."/controller/extender/event/controller/ajax_controller.php?act=refundOrder&nid=".$event_member_info['nid']."&price=".$v2['pay_price'];
                    echo "<br/>";

                    file_get_contents($_url);

                    //如果使用了优惠券，就把优惠券核销
                    if($v2['coupon_id'] > 0){
                        $update_coupon_data['ai_is_use'] = 0 ;
                        $update_coupon_data['ai_update_time'] = time() ;
                        echo $sql = update_date($table_Prefix . 'coupon_member',$update_coupon_data,'nid',$v2['coupon_id']);
                        $res = do_query($sql);
                    }

                }






        }

    }
}
?>
